using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Toenda.Rails.System;
using Toenda.Rails.DataContainer;

public partial class Controls_Main_ctrl_createset : System.Web.UI.UserControl {
	private AccountProvider ap = new AccountProvider();
	private ImageProvider ip = new ImageProvider();

	/// <summary>
	/// Page_Load
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	protected void Page_Load(object sender, EventArgs e) {
		if(!IsPostBack) {
			if(Session.Count > 0 && ap.CheckSessionExist(Session["Zappr"].ToString())) {
			}
			else {
				Response.Redirect("~/login.aspx");
			}
		}
	}

	/// <summary>
	/// btnSave_Click
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	protected void btnSave_Click(object sender, EventArgs e) {
		if(Session.Count > 0 && ap.CheckSessionExist(Session["Zappr"].ToString())) {
			Account acc = ap.GetAccountBySession(Session["Zappr"].ToString());
			SetItem item = new SetItem();

			item.Access = Convert.ToInt32(rblPrivacy.SelectedValue);
			item.Name = txtTitle.Text.Trim();
			item.Description = txtDesc.Text.Trim();
			item.CreateDate = DateTime.Now;
			item.UserID = acc.ID;

			SetItem s = ip.SaveSet(item, true);

			//Response.Redirect("default.aspx?set=" + s.SetID.ToString());
			Response.Redirect("~/set/" + s.SetID.ToString() + "/default.aspx");
		}
		else {
			Response.Redirect("~/login.aspx");
		}
	}

	/// <summary>
	/// btnCancel_Click
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	protected void btnCancel_Click(object sender, EventArgs e) {
		if(Session.Count > 0 && ap.CheckSessionExist(Session["Zappr"].ToString())) {
			Account acc = ap.GetAccountBySession(Session["Zappr"].ToString());

			//Response.Redirect("default.aspx?id=sets&user=" + acc.Username);
			Response.Redirect("~/sets/" + acc.Username + "/default.aspx");
		}
		else {
			Response.Redirect("~/login.aspx");
		}
	}
}
